<template>
	<coreshop-page title="订单提交" mode="left" needLoadingPage :loadingPage="loadingPage">
		<view class="layout-order-box p-25 m-b-25">
			<!-- 下单提醒 -->
			<view class="remind-box">
				<view class="title">下单提醒</view>
				<view class="desc">
					选择【同城配送】下单将产生运费，由我们进行配送，选择【门店自提】下单，请前往门店提供订单手机号码或者核销码进行核销取货。
				</view>
			</view>
			<!-- 配送方式 -->
			<view class="tab-box">
				<template v-for="item in state.tabList" :key="item.type">
					<view :class="['item', { 'on': state.tabSelectType === item.type }]" v-if="item.show"
						@click="handleChangeTab(item.type)">{{ item.name }}</view>
				</template>
			</view>
			<!-- 地址 -->
			<view class="address-box"
				v-if="state.tabSelectType === OrderDistributionEnum.mailing || state.tabSelectType === OrderDistributionEnum.homeDelivery">
				<view class="address-content">
					<view v-if="Object.keys(state.userDefaultShip).length > 0" class="have-address"
						@click="handleRouteNavigateTo(`/pages/subpackage/member/address/list/list?type=select`)">
						<view class="address">
							<text class="name">{{ state.userDefaultShip.name }}</text>
							<text class="mobile">{{ state.userDefaultShip.mobile }}</text>
						</view>
						<view class="street">{{ state.userDefaultShip.areaName }} {{ state.userDefaultShip.address }} {{
                            state.userDefaultShip.street }}</view>
					</view>
					<view v-else class="no-address"
						@click="handleRouteNavigateTo(`/pages/subpackage/member/address/list/list?type=select`)">
						请添加收货地址
					</view>
					<view class="icon">
						<uv-icon name="arrow-right" color="#aaaaaa" size="20"></uv-icon>
					</view>
				</view>
				<view class="address-line"></view>
			</view>
			<!-- 门店自提 -->
			<view class="store-pickup-box" v-if="state.tabSelectType === OrderDistributionEnum.selfDelivery">
				<view class="pickup-box" @click="handleRouteNavigateTo(`/pages/order/storeList/storeList`)">
					<view class="store-box" v-if=" state.store && Object.keys(state.store).length > 0">
						<view class="store-address-box">
							<view class="store-address">
								<text class="name">{{ state.store?.storeName }}</text>
								<text class="mobile">{{ state.store?.mobile }}</text>
							</view>
							<view class="street">{{ state.store?.address }}</view>
						</view>
						<view class="icon">
							<uv-icon name="arrow-right" color="#aaaaaa" size="20"></uv-icon>
						</view>
					</view>
					<view class="store-box" v-else>
						<view class="no-store">请选择门店</view>
						<uv-icon name="arrow-right" color="#aaaaaa" size="18"></uv-icon>
					</view>
					<view class="address-line"></view>
				</view>
				<!-- 姓名电话填写 -->
				<view class="user-box" v-if="shopConfigStore?.config?.storeSwitch == ShowStoresSwitchEnum.yes">
					<view class="user m-b-15">
						<view class="lab">姓名</view>
						<view class="val">
							<uv-input placeholder="请输入姓名" border="surround" v-model="state.storePick.name"></uv-input>
						</view>
					</view>
					<view class="user">
						<view class="lab">电话</view>
						<view class="val">
							<uv-input placeholder="请输入电话" border="surround" v-model="state.storePick.mobile"
								type="number"></uv-input>
						</view>
					</view>
				</view>
			</view>
			<!-- 商品 -->
			<view class="goods-box">
				<view class="item-goods" v-for="item in state.cartData?.list" :key="item.id">
					<view class="m-b-20">
						<coreshop-goods-card type="horizontal" imgHeight="160rpx" imgWidth="160rpx"
							:goodsData="hanldeCombinationGoodsData(item)" :nameOverflow="2">
							<template #goodPrice>
								<view class="price-msg">
									<view class="price">
										<text class="symbol">￥</text>
										<text class="num">{{ item?.products?.price || 0 }}</text>
									</view>
									<view class="buyCount">x{{ item?.nums || '' }}</view>
								</view>
							</template>
						</coreshop-goods-card>
					</view>
					<view class="promotion-box" v-if="Object.keys(item.products.promotionList).length > 0">
						<view class="promotion" v-for="cell, cellIndex in item.products.promotionList" :key="cellIndex">
							<uv-tags :text="cell.name" plain size="mini" type="success"></uv-tags>
						</view>
					</view>
					<view class="point-price" v-if="isShowPointRedemptionPrice && item.products.pointsDeduction > 0">
						<view class="lab">
							{{ shopConfigStore?.config?.pointShowName }}兑换价：
						</view>
						<view class="val">
							{{ shopConfigStore?.config?.pointDiscountedProportion * item.products.pointsDeduction }}{{
                                shopConfigStore?.config?.pointShowName }} +
							￥{{ parseFloat(String((item.products.price -
                                item.products.pointsDeduction) * item.nums)).toFixed(2) }}
						</view>
					</view>
					<view class="total-point-price">
						<view class="point" v-if="isShowPointRedemptionPrice && item.products.pointsDeduction > 0">
							<view class="lab">
								{{ shopConfigStore?.config?.pointShowName }}兑换价合计：
							</view>
							<view class="val">
								{{ shopConfigStore?.config?.pointDiscountedProportion * item.products.pointsDeduction *
                                    item.nums
                                }}{{ shopConfigStore?.config?.pointShowName }} +
								￥{{ parseFloat(String((item.products.price -
                                    item.products.pointsDeduction) * item.nums)).toFixed(2) }}
							</view>
						</view>
						<view class="give" v-if="isShowBuyGivePoint && item.products.points > 0">
							<view class="lab">
								购买将赠送：
							</view>
							<view class="val">
								{{ item.products.points * item.nums }}{{ shopConfigStore?.config?.pointShowName }}
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 优惠券 -->
			<view class="coupon-box"
				v-if="state.userCouponsList.length > 0 && state.orderType === PaymentTypeEnum.common && shopConfigStore.config.showCoupon === ShowCouponEnum.yes">
				<view class="title-box">
					<view class="title">优惠券</view>
					<view class="desc" v-if="state.couponCodeList.length > 0" @click="handleCancelSelectCoupop">取消选择
					</view>
				</view>
				<view class="list-box">
					<scroll-view class="coupon-scroll" scroll-x>
						<view class="coupon-item" v-for="item in state.userCouponsList" :key="item.couponCode"
							@click="handleSelectCoupop(item)">
							<view class="name">{{item.couponName}}</view>
							<view class="expression">{{item.expression2}}</view>
							<view class="time">有效期：{{ item.stime + ' 至 ' + item.etime }}</view>
							<view :class="['select',{'on':item.checked}]">
								<view class="icon">
									<uv-icon name="checkbox-mark" color="#fff" size="22"></uv-icon>
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
			<!-- 发票 -->
			<view class="invoice-point">
				<view class="point-box"
					v-if="shopConfigStore.config.pointSwitch === OpenPointEnum.yes && state.userPointData?.point > 0 && state.orderType === PaymentTypeEnum.common">
					<view class="title-box">
						<view class="tit">积分抵扣</view>
						<view class="desc">可用 {{ state.userPointData?.availablePoint }}
							{{ shopConfigStore?.config?.pointShowName }}
							，可抵扣 {{ state.userPointData?.pointExchangeMoney }} 元，共有 {{ state.userPointData?.point }}
							{{ shopConfigStore?.config?.pointShowName }}
						</view>
					</view>
					<view class="icon">
						<uv-switch v-model="state.isUsePoint" @change="handleChangeIsUsePoint" activeColor="#D33123"
							size="20"></uv-switch>
					</view>
				</view>
				<view class="invoice-box" @click="handleRouteNavigateTo(`/pages/subpackage/member/invoice/set/set`)">
					<view class="tit">发票</view>
					<view class="icon">
						<view class="desc">{{ state.invoice?.name || '无' }}</view>
						<uv-icon name="arrow-right" color="#2C2C2B" size="16"></uv-icon>
					</view>
				</view>
			</view>
			<!-- 商品价格优惠等 -->
			<view class="goods-price-box">
				<view class="item">
					<view class="lab">订单总额</view>
					<view class="val price">￥{{ state.cartData?.goodsAmount || 0 }}</view>
				</view>
				<view class="item">
					<view class="lab">商品优惠</view>
					<view class="val">-￥{{ state.cartData?.goodsPromotionMoney || 0 }}</view>
				</view>
				<view class="item">
					<view class="lab">订单优惠</view>
					<view class="val">-￥{{ state.cartData?.orderPromotionMoney || 0 }}</view>
				</view>
				<view class="item">
					<view class="lab">优惠券优惠</view>
					<view class="val">-￥{{ state.cartData?.couponPromotionMoney || 0 }}</view>
				</view>
				<view class="item"
					v-if="shopConfigStore.config.pointSwitch === OpenPointEnum.yes && state.userPointData?.point > 0 && state.orderType === PaymentTypeEnum.common">
					<view class="lab">{{ shopConfigStore?.config?.pointShowName }}抵扣</view>
					<view class="val">-￥{{ state.cartData?.pointExchangeMoney || 0 }}</view>
				</view>
				<view class="item">
					<view class="lab">运费</view>
					<view class="val">￥{{ state.cartData?.costFreight || 0 }}</view>
				</view>
			</view>
			<!-- 买家留言 -->
			<view class="leave-msg">
				<view class="tit">买家留言</view>
				<uv-textarea v-model="state.leaveMsg" placeholder="请输入内容"></uv-textarea>
			</view>
			<!-- 底部按钮 -->
			<view class="fixed-box">
				<view class="fixed-btn">
					<view class="btn-box">
						<view class="total-box">
							<view class="total">共{{ productNums }}件商品</view>
							<view class="price">
								<text class="tit">合计</text>
								<text>￥{{ state.cartData?.amount }}</text>
							</view>
						</view>
						<coreshop-button class="btn" title="确认下单" @onClick="handleSubmit" :loading="loading"
							:customStyle="{'border':'none','height':'90rpx'}"></coreshop-button>
					</view>
				</view>
			</view>
		</view>
	</coreshop-page>
</template>
<script setup lang="ts">
	import { reactive, computed, ref } from 'vue';
	import { onLoad, onShow, onPullDownRefresh } from '@dcloudio/uni-app';
	import {
		PaymentTypeEnum, OrderDistributionEnum, ShowStoresSwitchEnum,
		OpenPointEnum, PointExchangeModelEnum, ShowPointExchangePriceEnum,
		PointsGiveModeEnum, ShowPointsGiveMsgEnum, OrderPayStatusEnum, ShowCouponEnum
	} from '@/core/enum';
	import { queryOrderDistributionModel, getSubscriptionTmplIds, queryCreateOrder, queryUserDefaultShip, queryDefaultStore, queryCartList, queryUserPoint, queryCartCoupon } from '@/core/api';
	import type { Response, AddressType, ShopConfigStoreType, StoreListType } from '@/core/models';
	import { useShopConfigStore } from '@/core/store';
	import { mobile } from '@/uni_modules/uv-ui-tools/libs/function/test.js';
	import { handleRouteNavigateTo, handleShowToast, handleRouteRedirectTo } from '@/core/utils';
	import { addressUserShip, userInvoice, userStore } from '@/core/consts';
	import { useLoadingFn } from '@/core/hooks';

	interface QueryParams {
		cartIds ?: string;
		orderType ?: number;
		objectId ?: number;
		teamId ?: number;
	}

	interface CartListCallBack {
		success : Function,
		file : Function,
	}

	interface TabList {
		name : string,
		type : OrderDistributionEnum;
		show : boolean;
	}

	/** 获取项目配置 */
	const shopConfigStore : ShopConfigStoreType = useShopConfigStore();
	const state = reactive<{
		orderType : PaymentTypeEnum;    // 订单类型
		tabList : Array<TabList>;       // 送达方式
		tabSelectType ?: OrderDistributionEnum; // 送达方式类型
		userDefaultShip : AddressType;  // 默认地址数据
		leaveMsg : string;              // 卖家留言
		cartData : any;                 // 商品购物车数据
		params : any;                   // 最后去支付提交的数据
		isUsePoint : boolean;           // 是否使用积分抵扣
		userPointData : any;            // 用户积分数据
		objectId : number;              // 关联对象序列
		teamId : number;                // 拼团订单分组序列
		storePick : {                   // 自提姓名电话
			name : string;
			mobile : string;
		};
		invoice : any;                   // 发票信息
		store : StoreListType;           // 默认门店
		userCouponsList : Array<any>;    // 可用优惠券列表
		couponCodeList : Array<string>;    // 选中的优惠券code
	}>({
		orderType: PaymentTypeEnum.common,
		tabList: [
			{ name: '快递物流', type: OrderDistributionEnum.mailing, show: false, },
			{ name: '同城配送', type: OrderDistributionEnum.homeDelivery, show: false, }, 
			{ name: '门店自提', type: OrderDistributionEnum.selfDelivery, show: false, } 
		],
		tabSelectType: null,
		userDefaultShip: {},
		leaveMsg: "",
		cartData: {},
		params: {},
		isUsePoint: false,
		userPointData: {},
		objectId: 0,
		teamId: 0,
		storePick: {
			name: "",
			mobile: "",
		},
		invoice: {},
		store: {},
		userCouponsList: [],
		couponCodeList: [],
	});

	const loading = ref(false);
	const loadingPage = ref(true);
	const handleSubmit = useLoadingFn(onSubmit, loading);
	const handleGetOrderDetail = useLoadingFn(getOrderDetail, loadingPage);

	/** 是否显示积分兑换价合计 */
	const isShowPointRedemptionPrice = computed(() => {
		return shopConfigStore.config.pointSwitch == OpenPointEnum.yes &&
			shopConfigStore.config.pointExchangeModel == PointExchangeModelEnum.single &&
			shopConfigStore.config.pointShowExchangePrice == ShowPointExchangePriceEnum.yes && state.orderType == PaymentTypeEnum.common;
	})

	/** 是否显示购买送积分 */
	const isShowBuyGivePoint = computed(() => {
		return shopConfigStore.config.pointSwitch == OpenPointEnum.yes &&
			shopConfigStore.config.pointGetModel == PointsGiveModeEnum.single &&
			shopConfigStore.config.pointShowPoint == ShowPointsGiveMsgEnum.yes;
	})

	/** 共计多少件商品 */
	const productNums = computed(() => {
		let nums : number = 0;
		state.cartData?.list?.forEach((item : any) => {
			if (item.isSelect) {
				nums += item.nums;
			}
		})
		return nums;
	})

	onShow(() => {
		/** 选择地址后进来 */
		let userShip = uni.getStorageSync(addressUserShip);
		if (userShip) {
			state.userDefaultShip = userShip;
			state.params.userShipId = userShip.id;
			state.params.areaId = userShip.areaId;

			state.storePick.name = userShip.name;
			state.storePick.mobile = userShip.mobile;
			getCartList();
			uni.removeStorage({ key: addressUserShip });
		}

		/** 选择门店后进来 */
		let store = uni.getStorageSync(userStore);
		if (store) {
			state.store = store;
			uni.removeStorage({ key: userStore });
		}

		/** 选择发票后进来  确认下单的时候，要删除掉 */
		let userInvoiceInfo = uni.getStorageSync(userInvoice);
		if (userInvoiceInfo) {
			state.invoice = userInvoiceInfo;
		} else {
			state.invoice = {};
		}
	});

	onLoad(async (query : QueryParams) => {
		state.params.ids = query?.cartIds;
		/** 订单类型 */
		if (query.orderType) {
			state.orderType = query.orderType;
		}
		/** 关联对象序列 */
		if (query.objectId) {
			state.objectId = query.objectId;
		}
		/** 拼团订单分组序列 */
		if (query.teamId) {
			state.teamId = query.teamId;
		}
		handleGetOrderDetail();
	});

	onPullDownRefresh(async () => {
		await handleGetOrderDetail();
		uni.stopPullDownRefresh();
	});

	async function getOrderDetail() {

		/** 获取不同类型,营销下单支持的配送方式 */
		await getOrderDistributionModel();
		/** 获取用户的可用优惠券信息 */
		await getUserCounpons();
		/** 如果店铺开启，获取默认店铺 */
		if (shopConfigStore?.config?.storeSwitch == ShowStoresSwitchEnum.yes) {
			await getDefaultStore();
		}
		/** 获取用户默认地址 */
		await getUserDefaultShip();
	}


	/** 获取商品详情 */
	const getCartList = async (data ?: CartListCallBack) => {
		state.params.receiptType = state.tabSelectType;

		const cartList : Response<any> = await queryCartList({
			...state.params,
			objectId: state.objectId,
			point: state.isUsePoint ? state.userPointData?.availablePoint : 0,
			type: state.orderType,
			couponCode: state.couponCodeList.length > 0 ? state.couponCodeList.join(',') : '',
		});
		if (cartList.status) {
			state.cartData = cartList?.data;

			/** 判断是否有库存 */
			let noStockGood = cartList?.data?.list?.filter((item : any) => !item.isSelect);;
			if (noStockGood.length > 0 || cartList?.data?.list?.length == 0) {
				uni.showModal({
					title: '提示',
					content: `所挑选的商品已售罄，请重新添加哦`,
					showCancel: false
				});
			}
			/** 判断是否开启积分抵扣 并且 没有勾选积分使用 */
			if (shopConfigStore.config.pointSwitch === OpenPointEnum.yes && !state.isUsePoint) {
				getUserPoint(cartList?.data?.amount)
			}
			data?.success(cartList);
		} else {
			data?.file(cartList);
		}
	}

	/** 判断用户下单可以使用多少积分  */
	const getUserPoint = async (amount : number) => {
		const userPoint : Response<any> = await queryUserPoint({
			cartType: state.orderType,
			ids: state.params.ids,
			orderMoney: amount
		});
		if (userPoint.status) {
			/** 用户总积分 point  
			 * 可以使用的积分 availablePoint 
			 * 积分抵扣的总金额 pointExchangeMoney */
			state.userPointData = userPoint?.data;
		}
	}

	/** 获取不同类型,营销下单支持的配送方式 */
	const getOrderDistributionModel = async () => {
		const orderDistribution : Response<any> = await queryOrderDistributionModel({
			id: state.orderType,
		});

		if (!orderDistribution?.data || Object.keys(orderDistribution?.data).length === 0) {
			handleShowToast('暂无下单配送方式');
			return;
		}
		const { isOpenMailing, isOpenHomeDelivery, isOpenSelfDelivery } = orderDistribution?.data;
		if (!isOpenMailing && !isOpenHomeDelivery && !isOpenSelfDelivery) {
			handleShowToast('暂无下单配送方式');
			return;
		}

		/** 物流快递 */
		state.tabList[0].show = isOpenMailing;
		/** 同城配送 */
		state.tabList[1].show = isOpenHomeDelivery;
		/** 门店自提 */
		state.tabList[2].show = isOpenSelfDelivery;

		state.tabSelectType = (state.tabList.find((item : TabList) => item.show))?.type || OrderDistributionEnum.mailing;
	}

	/** 获取用户默认地址 */
	const getUserDefaultShip = async () => {
		const userDefaultShip : Response<AddressType> = await queryUserDefaultShip();
		if (userDefaultShip?.data && Object.keys(userDefaultShip.data).length > 0) {
			state.userDefaultShip = userDefaultShip.data;
			state.params.userShipId = userDefaultShip.data?.id;
			state.params.areaId = userDefaultShip.data?.areaId;
			state.storePick.name = userDefaultShip?.data?.name;
			state.storePick.mobile = userDefaultShip?.data?.mobile;
		}
		getCartList();
	}

	/** 获取用户的可用优惠券信息 */
	const getUserCounpons = async () => {
		const cartCoupon : Response<any> = await queryCartCoupon({
			display: 'no_used',
			ids: state.params.ids
		});
		if (cartCoupon.status && cartCoupon.data?.list) {
			let nowTime = Math.round(new Date().getTime() / 1000).toString();
			state.userCouponsList = cartCoupon.data.list.map((item : any) => {
				item['checked'] = false;
				item['disabled'] = item.startTime > nowTime ? true : false;
				return item;
			})
		}
	}

	/** 取消使用优惠券 */
	const handleCancelSelectCoupop = () => {
		state.userCouponsList.forEach((item : any) => {
			item.checked = false;
		})
		state.couponCodeList = [];
		getCartList();
	}

	/** 选择使用优惠券 */
	const handleSelectCoupop = (item : any) => {
		if (!item.disabled) {
			handleShowToast('请在有效时间内使用');
			return;
		}

		if (state.couponCodeList.includes(item.couponCode)) {
			state.couponCodeList.splice(state.couponCodeList.findIndex((cell) => cell == item.couponCode), 1);
		} else {
			state.couponCodeList.push(item.couponCode);
		}

		getCartList({
			success() {
				item.checked = !item.checked;
			},
			file(data : any) {
				handleShowToast(data.msg);
				state.couponCodeList.splice(state.couponCodeList.findIndex((cell) => cell == item.couponCode), 1);
				item.checked = false;
			}
		})
	}

	/** 获取默认店铺 */
	const getDefaultStore = async () => {
		const defaultStore : Response<StoreListType> = await queryDefaultStore();
		if (defaultStore.status && defaultStore.data) {
			state.store = defaultStore.data;
		}
	}

	/** 切换tab配送方式 */
	const handleChangeTab = (type : number) => {
		if (state.tabSelectType != type) {
			state.tabSelectType = type;
			getCartList();
		}
	}

	/** 组合商品数据传入组件 */
	const hanldeCombinationGoodsData = (item : any) => {
		return {
			image: item.products.images,
			name: item.products.name,
			brief: item.products.spesDesc,
			price: item.products.price,
		}
	}

	/** 是否使用积分 */
	const handleChangeIsUsePoint = async (e : any) => {
		state.params.point = state.isUsePoint ? state.userPointData?.availablePoint : 0;
		/** 获取用户默认地址 */
		await getUserDefaultShip();
	}

	/** 立即购买 */
	async function onSubmit() {
		let delivery : any = {};
		if (!state.tabSelectType) {
			handleShowToast('请选择下单配送方式');
			return;
		}
		/** 如果是快递物流 / 同城送货 */
		if (state.tabSelectType === OrderDistributionEnum.mailing || state.tabSelectType == OrderDistributionEnum.homeDelivery) {
			if (!state.userDefaultShip.id || !state.userDefaultShip.areaId) {
				handleShowToast('请选择收货地址');
				return;
			}
			delivery = {
				ushipId: state.userDefaultShip.id,
				areaId: state.userDefaultShip.areaId
			}
		}
		/** 如果是自提 */
		if (state.tabSelectType === OrderDistributionEnum.selfDelivery) {
			if (!state.store.id) {
				handleShowToast('请选择自提门店');
				return;
			}
			if (!state.storePick.name) {
				handleShowToast('请输入提货人姓名');
				return;
			}
			if (!state.storePick.mobile) {
				handleShowToast('请输入提货人手机号');
				return;
			}
			if (!mobile(state.storePick.mobile)) {
				handleShowToast('提货人手机号输入错误');
				return;
			}
			delivery = {
				storeId: state.store.id,
				ladingName: state.storePick.name,
				ladingMobile: state.storePick.mobile
			}
		}
		let data : any = {
			...delivery,
			cartIds: state.params.ids,
			memo: state.leaveMsg,
			couponCode: state.couponCodeList.length > 0 ? state.couponCodeList.join(',') : '',
			point: state.params.point,
			receiptType: state.tabSelectType,
			objectId: state.objectId,
			teamId: state.teamId,
			orderType: state.orderType,
			requireOrder: 0,
			requiredFundType: 0,
			traceId: "",
			/** 发票信息 */
			taxType: state.invoice?.type,
			taxName: state.invoice?.name,
			taxCode: state.invoice?.code,
		}
		// #ifdef MP-WEIXIN
		data['source'] = 3;
		// #endif
		// #ifdef MP-ALIPAY
		data['source'] = 4;
		// #endif
		// #ifdef APP-PLUS || APP-PLUS-NVUE
		data['source'] = 5;
		// #endif
		// #ifdef MP-TOUTIAO
		data['source'] = 6;
		// #endif
		const createOrder : Response<any> = await queryCreateOrder(data);
		if (createOrder.status) {
			uni.removeStorage({ key: userInvoice });
			// 判断是否为0元订单,如果是0元订单直接支付成功
			if (createOrder.data.payStatus == OrderPayStatusEnum.yes) {
				handleRouteRedirectTo(`/pages/order/result/result?orderId=${createOrder.data.orderId}`);
			} else {
				handleRouteRedirectTo(`/pages/order/pay/pay?orderId=${createOrder.data.orderId}&orderType=${state.orderType}`);
			}
			//发起订阅
			// #ifdef MP-WEIXIN
			subscription();
			// #endif
		} else {
			handleShowToast(createOrder.msg);
		}
	}

	/** 订阅 */
	const subscription = async () => {
		const ids : Response<any> = await getSubscriptionTmplIds();
		if (ids.status && ids.data.length > 0) {
			wx.getSetting({
				withSubscriptions: true,
				success() {
					if (wx.requestSubscribeMessage) {
						wx.requestSubscribeMessage({
							tmplIds: ids.data,  //购买，发货，收货通知
							success: function () { },
							fail: function () { }
						})
					} else {
						handleShowToast('请更新您微信版本，来获取订阅消息功能');
					}

				}
			});
		} else {
			handleShowToast(ids.msg);
		}
	}
</script>
<style lang="scss" scoped>
	@import './submit.scss';
</style>